Skip to content

fix(frontend): clear stale streamingSessionId on session reopen - #1257

Open
iagop03 wants to merge 1 commit into
HKUDS:mainfrom
iagop03:fix/stale-streaming-session-indicator
Open

fix(frontend): clear stale streamingSessionId on session reopen#1257
iagop03 wants to merge 1 commit into
HKUDS:mainfrom
iagop03:fix/stale-streaming-session-indicator

Conversation

@iagop03

@iagop03 iagop03 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes the sidebar "thinking" spinner for a session getting permanently stuck once you navigate away from it mid-turn, even long after that turn actually finishes.

Why

Closes #1256.

streamingSessionId (the store field the sidebar spinner reads) is deliberately preserved when you switch sessions, so it can keep showing progress for a session you've left. But the same session-switch effect also tears down that session's SSE connection (doDisconnect()), so the session_completed event that would normally clear the marker never arrives. Reopening the session later doesn't help either — /events?replay=active only replays buffered events for a still-running attempt, so there's nothing to reconcile against once it has already completed. The one function that does this reconciliation (syncCompletedAttempt) is only ever invoked right after the local client sends a message, never on session (re)open.

Net effect: leave a streaming session, and its sidebar spinner is wrong forever, until a full page reload.

Changes

  • frontend/src/pages/Agent.tsx: in loadSessionMessages (already called on every session open/reopen, and already fetching that session's full committed history), if the session being loaded is the one marked as streamingSessionId and its newest stored message is already the assistant's reply, clear the stale marker via clearStreamingSession. No extra network request — reuses data already fetched for this call.
  • frontend/src/pages/__tests__/AgentBackgroundStreamCompletion.test.tsx: new regression test covering both the fix (stale marker clears once the reply is committed) and the negative case (marker is left alone when the background session genuinely has no reply yet, i.e. still running).

Test Plan

  • New test added: npx vitest run src/pages/__tests__/AgentBackgroundStreamCompletion.test.tsx — 2/2 passing.
  • Full frontend suite: npx vitest run --pool=threads — 596/598 passing; the 2 failures (options.test.ts ivLabel decimal-separator formatting, tearsheet.test.ts UTC-5 timezone-offset assumption) are pre-existing and locale/timezone-environment-dependent, unrelated to this change (reproduce identically on main without this diff).
  • npx tsc -b — clean.
  • Not tested against a live browser session manually; verified via the unit test's simulated navigation instead.

Checklist

  • No changes to protected areas (src/agent/, src/session/, src/providers/)
  • No hardcoded values
  • Follows CONTRIBUTING.md (DCO sign-off on the commit)
  • No user-facing docs needed — pure bugfix, no new config/flags/behavior to document

The sidebar's "thinking" spinner for a backgrounded session
(streamingSessionId) never cleared once its turn actually finished, because:

- switchSession() deliberately preserves streamingSessionId across a
  navigation so the sidebar can keep showing progress for a session you've
  left, but the same switch effect also disconnects that session's SSE
  stream (doDisconnect()), so the session_completed event that would
  normally clear the marker (via clearStreamingSession) never arrives.
- Reopening the session doesn't help either: /events?replay=active only
  replays buffered events for a still-running attempt, so there's nothing
  to reconcile against for one that already completed.

loadSessionMessages() already fetches the session's full committed history
on every open/reopen. If the session being loaded is the one currently
marked as streaming and its newest stored message is the assistant's reply,
that turn is done -- release the stale marker using data already in hand,
no extra request needed.

Closes HKUDS#1256

Signed-off-by: Iago Pueyo <iago.pueyo99@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidebar "thinking" indicator never clears for a session backgrounded mid-turn

1 participant